package org.oaix.proxy.jdk;

import org.oaix.proxy.Person;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class PersonInvocation implements InvocationHandler {

	private Object target;

	public PersonInvocation(){

	}
	public PersonInvocation(Object target){
		this.target=target;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("代理。。。方法。。。start");
		Object object=method.invoke(target,args);
		System.out.println("代理。。。方法。。。end");
		return object;
	}

	public static void main(String[] args) {
		Run person=new Person() ;
		person= (Run) Proxy.newProxyInstance(person.getClass().getClassLoader(),person.getClass().getInterfaces(),new PersonInvocation(person));
		person.add(1);
	}
}
